/**********************************************************************************
// Asteroids
//
// Creation:	14 Set 2008
// Updated:		17 Out 2009
// Compiler:	Visual Studio 2008
//
// Notes:		Test the Anabele engine
//				Remake of classical asteroids game
//
**********************************************************************************/

#ifndef _ASTEROIDSRACE_H_
#define _ASTEROIDSRACE_H_

#define WIN32_LEAN_AND_MEAN  // just say no to MFC

#include "Resources.h"
#include "Anabele.h"	
#include "SpaceShip.h"
#include "Rock.h"
#include "Missile.h"
#include "StarField.h"
#include "Explosion.h"

#include <fstream>
#include <algorithm>
#include <iterator>
#include <list>
using std::list;

/**********************************************************************************/
/*                            Asteroids Class                                     */
/**********************************************************************************/

// game sounds id's
enum Sounds {UP, DOWN, PULSE, EXPLOSION, MISSILEHIT, BLOW, BEEP, INTRO, TRANSITION, LEVELUP};

// game states
enum State 
{
	HOME, 
	PLEVEL1, LEVEL1, 
	PLEVEL2, LEVEL2, 
	PLEVEL3, LEVEL3, 
	PLEVEL4, LEVEL4, 
	GAMECOMPLETE, 
	LEVELCOMPLETE, 
	GAMEOVER
};

#define MAXBUFFER 120
#define NUMLEVELS 4


/**********************************************************************************/

class Asteroids: public D3DGame
{
private:
	SceneManager scene;					// game scene manager
	Sound snd;							// game sound system
	Input input;						// game input system

	float records[NUMLEVELS];			// the best times for each level 
	float overallRecord;				// the best overall result of a single play
	float theoreticalBest;				// the best overall result of all plays
	float playerHistory[NUMLEVELS];		// player time for all levels
	float playerTime;					// player time for current level
	float playerOverall;				// player sum of times for all levels

	int  gameState;						// current game state
	int  prevState;						// previous game state 
	char text[MAXBUFFER];				// text text for text output
	int midX, midY;					// center of the screen coordinates
	int finPosX, finPosY;				// finish marker screen coordinates

	int gameWorldWidth;					// game world with in pixels
	int gameWorldHeight;				// game world height in pixels
	Background * backg;					// background image
	RECT viewport;						// size of the viewport

	LARGE_INTEGER start, end;			// start and end values of high frequency counter
	LARGE_INTEGER freq;					// frequency of counter
	LONGLONG      timeLimit;			// time limit to finish current level
	LONGLONG      secs, milisecs;		// remaining seconds and miliseconds in the level

	StarField * eSpace;					// starfield background effect
	Sprite    * logo;					// game openning image
	Poly		ballons[5];				// messages ballons 
	Rect        border[4];				// screen borders
	Rect		finish;					// finish banner
	
	SpaceShip   ship;					// player's ship
	
	Color       finishColor;			// color to use on results	
	
	list<Rock *> rocks;					// list of rocks in the current level
	list<Rock *>::iterator iroc;		// iterator for rocks list

	list<Missile *> missiles;			// list of missiles in the current level
	list<Missile *>::iterator imis;		// iterator for missiles list

	list<Geometry *> fixed;				// list of fixed objects
	list<Geometry *>::iterator ifix;	// iterator for fixed objects list

	list<Explosion *> explosions;		// list of explosion objects
	list<Explosion *>::iterator iexp;	// iterator for explosion objects list

protected:
	void UnloadResources();				// unload device dependent resources when device is lost
	void LoadResources();				// load device dependent resources when device is operational

public:
	void GameInit();					// overwritten method
	void GameLogic();					// overwritten method
	void GameDraw();					// overwritten method
	void GameShutdown();				// overwritten method
	
	// Game Title
	void GameTitleLogic();				// logic for home screen
	void GameTitleDraw();				// drawing for home screen
	
	// Game Over
	void GameOverLogic();				// logic for game over
	void GameOverDraw();				// drawing for game over

	// Level Complete
	void LevelCompleteLogic();			// logic for level complete
	void LevelCompleteDraw();			// drawing for level complete

	// Game Complete
	void GameCompleteLogic();			// logic for game complete
	void GameCompleteDraw();			// drawing for game complete

	// Level 1
	void Level1Init();					// level 1 initialization
	void Level1Logic();					// level 1 game logic
	void Level1Draw();					// level 1 draw procedures
	void Level1CleanUp();				// level 1 clean up

	// Level 2
	void Level2Init();					// level 2 initialization
	void Level2Logic();					// level 2 game logic
	void Level2Draw();					// level 2 draw procedures
	void Level2CleanUp();				// level 2 clean up

	// Level 3
	void Level3Init();					// level 3 initialization
	void Level3Logic();					// level 3 game logic
	void Level3Draw();					// level 3 draw procedures
	void Level3CleanUp();				// level 3 clean up

	// Level 4
	void Level4Init();					// level 4 initialization
	void Level4Logic();					// level 4 game logic
	void Level4Draw();					// level 4 draw procedures
	void Level4CleanUp();				// level 4 clean up
};

/**********************************************************************************/

#endif